package com.seven.micro_service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;


@Component
public class DBInitializer {
    JdbcTemplate jdbcTemplate;
    @Autowired
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @PostConstruct
    public void init() {
        jdbcTemplate.update("CREATE TABLE IF NOT EXISTS user ("
                + "id VARCHAR (100) NOT NULL PRIMARY KEY, "
                + "pwd VARCHAR(100) NOT NULL)"
        );

        jdbcTemplate.update("CREATE TABLE IF NOT EXISTS authority("
                + "id VARCHAR (100) NOT NULL , "
                + "service VARCHAR(100) NOT NULL,"
                + "authorization bool NOT NULL, "
                + "PRIMARY KEY(id,service));"
        );
    }
}
